// pages/malltaskPackage/pages/order/order.js
const app = getApp();
const quote = app.globalData.quote;
const path = quote.paths;
const util = require('../../../../utils/util.js');
const tools = require('../../../../utils/tools.js');
const api = require('../../../../utils/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ordereList:[],
    cateID: 0, //当前分类id
    page: 0, //页码
    pageSize: 10, //页大小
    noData: true,
    isData: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that  = this
    this.ordereList()
  },
    // 更改当前分类id
  changeCateID(e) {
    console.log(e)
    this.setData({
      cateID: e.currentTarget.dataset.id,
      page: 0,
      ordereList: [],
      isData: false,
    })
    this.ordereList();

  },
  //订单列表
  ordereList:function(){
    var that = this
    if (this.data.isData) {
      return
    }
       wx.showLoading({
      title: '加载中',
    })

    let dataDic = {
       UCUID: 10015,
      LostType: that.data.cateID,
      pageIndex: that.data.page,
      pageSize: that.data.pageSize
    };
    api.methodEnglishCorner_MyOrder({
      dataDic,
      success:function(res){
        console.log(res.data.data.RecordList,'54订单列表RecordList')
        wx.hideLoading();
        let length = res.data.data.RecordList.length;
        if (length == 0) {
          that.setData({
            isData: true
          })
        }
        that.setData({
          page: that.data.page + 1,
       //   ordereList: res.data.data.RecordList
          ordereList: that.data.ordereList.concat(res.data.data.RecordList)
        })
        that.isNoData()
      }
      
    })

  },
  // 是否没有数据
  isNoData() {
    if (this.data.ordereList.length > 0) {
      this.setData({
        noData: true,
      })
    } else {
      this.setData({
        noData: false,
      })
    }
  },
  //复制兑换码
  Exchange:function(e){
    var code = e.currentTarget.dataset.code
   var that = this
    wx.setClipboardData({
      data: code,
      success: (res) => {
        wx.getClipboardData({
          success: (res) => {
            console.log(res)
            wx.showToast({
              title: '兑换码已复制',
              icon: 'success',
              duration: 1000
            })
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('滚到底部了')
    this.ordereList();
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})